home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / unclcarl / umaus207 / spriter.lst < prev    next >
File List  |  1995-04-25  |  6KB  |  166 lines

  1. ' SPRITER.LST
  2. ' Make sure a JOYSTICK is connected !
  3. ' I had one connected to PORT 2 so I'm not CERTAIN it will work with any
  4. ' other PORT (although it should). SMILEY1.CUR and SMILEY2.CUR were the
  5. ' sprites used when putting together this code, so you should load THEM
  6. ' (although you really can load ANY two sprite CUR files you like).
  7. '
  8. ' Moving the JOYSTICK moves the sprite and prints the sprite direction
  9. ' on the top of the screen (as well as the fire button status).
  10. '
  11. ' This file was created on an STe and should work on all ST/STe's in
  12. ' L/M/H resolution. I don't know if it will work anywhere else.
  13. ' ---------------------------------------------------------------------|
  14. @limits                ! DETERMINE SCREEN X,Y,W,H
  15. @lode.sprite
  16. ' ---------------------| LOAD SPRITES
  17. > PROCEDURE lode.sprite
  18.   ' ----------------------------|LOAD FIRST CURSOR
  19.   ti$="LOAD FIRST CURSOR"
  20.   PRINT AT(1,1);ti$
  21.   '
  22.   ' #ti$ below is used by TOS 1.4+ to put a "message" in the fileselector.
  23.   ' If you don't have TOS 1.4+ your system will simply ignore #ti$
  24.   ' IOW: You can leave it in, it won't hurt anything.
  25.   '
  26.   FILESELECT #ti$,"\*.CUR","SPRITE_1.CUR",file$
  27.   IF file$=""
  28.     EDIT
  29.   ENDIF
  30.   OPEN "I",#1,file$       ! Open ("I"nput ) the file
  31.   INPUT #1,dummy$         ! Input my personal file identifier
  32.   IF dummy$<>"' UMSP25"   ! If file ID is incorrect
  33.     '
  34.     ALERT 3,"|This is NOT a valid |sprite .CUR file ! ",1," Abort ",lk%
  35.     '
  36.     CLOSE #1              ! Remember to CLOSE the file !
  37.     END
  38.   ENDIF
  39.   l$=INPUT$(1,#1)         ! Input first string (character) in string
  40.   l%=ASC(l$)              ! Return ASCII code of the first string in l$
  41.   m1$=INPUT$(l%,#1)       ! Input string (length of string, #1)
  42.   CLOSE #1                ! Close file
  43.   ' ----------------------------|LOAD SECOND CURSOR
  44.   ti$="LOAD SECOND CURSOR"
  45.   PRINT AT(1,1);ti$
  46.   FILESELECT #ti$,"\*.CUR","SPRITE_2.CUR",file2$
  47.   IF file2$=""
  48.     EDIT
  49.   ENDIF
  50.   OPEN "I",#1,file2$
  51.   INPUT #1,dummy$
  52.   IF dummy$<>"' UMSP25"
  53.     ALERT 3,"|This is NOT a valid |sprite .CUR file ! ",1," Abort ",lk%
  54.     CLOSE #1
  55.     END
  56.   ENDIF
  57.   l1$=INPUT$(1,#1)
  58.   l1%=ASC(l1$)
  59.   m2$=INPUT$(l1%,#1)
  60.   CLOSE #1
  61.   ' ----------------------------| JOYSTICK READER
  62.   @joystick
  63.   EDIT
  64. RETURN
  65. ' ---------------------| Set up IKBD to return the JOYSTICK packet
  66. > PROCEDURE joystick
  67.   '
  68.   mc$=MKI$(&H23C8)+MKL$(*a%)+MKI$(&H4E75)   !Convert numbers into char. string
  69.   '
  70.   v%=XBIOS(34)+24       !Address of table w/keyboard processor address.
  71.   o%=LPEEK(v%)          !read 4 bytes starting at address v%
  72.   LPOKE v%,VARPTR(mc$)  !write V:mc$ as a 4 byte value to the address v%
  73.   a%=0
  74.   OUT 4,&H16            !IKBD
  75.   '
  76.   REPEAT                ! Wait for interrupt
  77.   UNTIL a%              ! (the value of the joystick packet is stored in a%)
  78.   '
  79.   LPOKE v%,o%
  80.   joy_0%=a%+1
  81.   joy_1%=a%+2
  82.   OUT 4,&H14
  83.   '
  84.   PRINT AT(1,1);"Press any key to quit."
  85.   '
  86.   a=50                  ! SPRITE coordinates
  87.   b=50
  88.   SPRITE m1$,b,a        ! Place SPRITE on screen at 50,50
  89.   '
  90.   REPEAT
  91.     PRINT AT(1,2);"Joystick: ";(PEEK(a%) AND 1)+1
  92.     @output(PEEK(joy_1%))
  93.   UNTIL INKEY$<>""
  94.   OUT 4,8
  95. RETURN
  96. ' ---------------------| SPRITE OUTPUT CONTROL
  97. > PROCEDURE output(x%)
  98.   IF x% AND 128      ! JOYSTICK BUTTON
  99.     PRINT "Button"
  100.   ENDIF
  101.   IF x% AND 1        ! JOYSTICK UP
  102.     IF a>wy          ! If not at top of screen,
  103.       DEC a          ! continue up !
  104.     ENDIF
  105.     VSYNC            ! To reduce screen flicker
  106.     IF b<20          ! If sprite has changed due to screen location,
  107.       SPRITE m2$     ! clean up after 2nd sprite before moving up.
  108.     ENDIF
  109.     SPRITE m1$,b,a   ! Draw first sprite
  110.     PRINT "Up    "
  111.   ENDIF
  112.   IF x% AND 2        ! JOYSTICK DOWN
  113.     IF a<wh          ! If not at bottom of screen,
  114.       INC a          ! continue down !
  115.     ENDIF
  116.     VSYNC
  117.     IF b<20          ! If sprite has changed due to screen location,
  118.       SPRITE m2$     ! clean up after 2nd sprite before moving down.
  119.     ENDIF
  120.     SPRITE m1$,b,a   ! Draw first sprite
  121.     PRINT "Down  "
  122.   ENDIF
  123.   IF x% AND 4        ! JOYSTICK LEFT
  124.     IF b>wx+10       ! If not at left (plus 10 keeps it "on-screen"),
  125.       DEC b          ! continue left !
  126.     ENDIF
  127.     IF b>20          ! If sprite is more than 20 from left,
  128.       VSYNC
  129.       SPRITE m1$,b,a   ! use first sprite
  130.     ELSE
  131.       VSYNC
  132.       SPRITE m1$       ! Clean up after first sprite and
  133.       SPRITE m2$,b,a   ! draw second sprite.
  134.     ENDIF
  135.     PRINT "Left  "
  136.   ENDIF
  137.   IF x% AND 8        ! JOYSTICK RIGHT
  138.     IF b<=ww-10      ! If not at right (minus 10 to keep it "on-screen")
  139.       INC b          ! continue right !
  140.     ENDIF
  141.     VSYNC
  142.     IF b<20          ! If sprite has changed due to screen location,
  143.       SPRITE m2$     ! clean up after second sprite before continuing right.
  144.     ENDIF
  145.     SPRITE m1$,b,a
  146.     PRINT "Right "
  147.   ENDIF
  148.   PRINT CHR$(27);"K"
  149. RETURN
  150. ' ---------------------| SCREEN LIMITS
  151. > PROCEDURE limits
  152.   ' You can use your own routines to determine screen x,y,w,h, especially
  153.   ' if your machine doesn't support LINE A variables.
  154.   wx=0                 !Screen x (left)
  155.   wy=10                !Screen y (top)
  156.   ww=INT{L~A-12}       !Screen w (right)
  157.   wh=INT{L~A-4}-10     !Screen h (bottom)
  158. RETURN
  159. ' ---------------------|
  160. ' ---------------------------------------------------------------------|
  161. ' This is my first attempt in "dealing" w/sprites, so obviously the code
  162. ' is not very efficient. SPRITER.LST is FREEWARE, so feel free to do
  163. ' whatever you deem fit with the code, I hope you find it somewhat useful.
  164. ' If nothing else you may have learned something you didn't know before !
  165. ' Happy Hacking !  --| Uncle Carl
  166.